package com.miyuan.wm.controller;

import com.alibaba.fastjson.JSON;
import com.miyuan.wm.request.AddGoodsRequestVo;
import com.miyuan.wm.request.QueryGoodsRequestVo;
import com.miyuan.wm.request.UpdateGoodsRequestVo;
import com.miyuan.wm.response.BaseResponse;
import com.miyuan.wm.response.PageResponse;
import com.miyuan.wm.response.QueryGoodByIdResponseVo;
import com.miyuan.wm.response.QueryGoodsResponseVo;
import com.miyuan.wm.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName GoodsController
 * @Description 货物管理控制器
 */
@RestController
@Api(description = "货物管理控制器", tags = {"货物管理"})
@RequestMapping(value = "/goods")
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "获取货物列表接口")
    @PostMapping("/queryGoods")
    public PageResponse<List<QueryGoodsResponseVo>> listGoods(@Valid @RequestBody QueryGoodsRequestVo requestVo) {
        log.info("获取货物列表接口请求参数：{}", JSON.toJSONString(requestVo));
        return goodsService.listGoods(requestVo);
    }

    @ApiOperation(value = "新增货物信息接口")
    @PostMapping("/addGoods")
    public BaseResponse<Boolean> addGoods(@Valid @RequestBody AddGoodsRequestVo requestVo) {
        log.info("新增货物信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return goodsService.addGoods(requestVo);
    }

    @ApiOperation(value = "修改货物信息接口")
    @PostMapping("/updateGoods")
    public BaseResponse<Boolean> updateGoods(@Valid @RequestBody UpdateGoodsRequestVo requestVo) {
        log.info("修改货物信息接口请求参数：{}", JSON.toJSONString(requestVo));
        return goodsService.updateGoods(requestVo);
    }

    @ApiOperation(value = "删除货物信息接口")
    @PostMapping("/deleteGoods")
    public BaseResponse<Boolean> deleteGoods(@RequestBody List<Integer> ids) {
        log.info("删除货物信息接口请求参数：{}", JSON.toJSONString(ids));
        return goodsService.deleteGoods(ids);
    }

    @ApiOperation(value = "查询货物信息，供下拉框使用")
    @GetMapping("/queryGoodsforSelect")
    public BaseResponse<List<QueryGoodsResponseVo>> queryGoodsforSelect() {
        return goodsService.queryGoodsforSelect();
    }

    @ApiOperation(value = "根据Id查询货物信息")
    @GetMapping("/queryGoodById")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "货物数据库Id")})
    public BaseResponse<QueryGoodByIdResponseVo> queryGoodById(@RequestParam int id) {
        return goodsService.queryGoodById(id);
    }

}
